package top.fongs.spring_security_jwt.domain.entity.users.user_detail;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;

@Data
public class UserDetail implements UserDetails, Serializable {

    private static final long serialVersionUID = 8662027100185870223L;

    private Long id;

    private Integer type;

    private String username;

    private String password;

    private String name;

    private String phone;

    private Integer expired;

    private Integer locked;

    private Integer enabled;

    private final Collection< ? extends GrantedAuthority > authorities;

    public UserDetail( Collection< ? extends GrantedAuthority > authorities ) {
        this.authorities = authorities;
    }

    public UserDetail( Long id, Integer type, String username, String password, String name, String phone, Integer expired, Integer locked, Integer enabled, Collection< ? extends GrantedAuthority > authorities ) {
        this.id = id;
        this.type = type;
        this.username = username;
        this.password = password;
        this.name = name;
        this.phone = phone;
        this.expired = expired;
        this.locked = locked;
        this.enabled = enabled;
        this.authorities = authorities;
    }

    @Override
    public Collection< ? extends GrantedAuthority > getAuthorities( ) {
        return this.authorities;
    }

    @Override
    public String getPassword( ) {
        return this.password;
    }

    @Override
    public String getUsername( ) {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired( ) {
        return false;
    }

    @Override
    public boolean isAccountNonLocked( ) {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired( ) {
        return true;
    }

    @Override
    public boolean isEnabled( ) {
        return true;
    }
}
